<?php
namespace app\home\controller;

use app\common\logic\HelpTo;
use app\common\component\help_to\HelpToService;

class Farming extends ControllerBase {
	public function _initialize() {
		$this -> checkLogin();
	}

    public function index() {
    	(new HelpTo()) -> overtimeHelpTo();

    	$resultHelpTos = (new HelpToService()) -> getHelpTos();
		$this -> view -> assign('help_tos', $resultHelpTos);

    	return $this -> view -> fetch();
    }

    public function record() {
    	$resultHelpTos = (new HelpToService()) -> getAll();
		$this -> view -> assign('help_tos', $resultHelpTos);

    	return $this -> view -> fetch();
    }

	public function firstConfirmHelpTo() {
		$post = $this -> request -> post();
		if($this -> validate($post, ['help_to_id' => 'require|token']) !== true) {
			return json(['code' => -1, 'message' => '请勿重复提交!']);
		}

		return json((new HelpTo()) -> firstConfirmHelpTo($post['help_to_id']));
	}

    public function confirmHelpTo() {
    	$post = $this -> request -> post();
		if($this -> validate($post, ['help_to_id' => 'require|token']) !== true) {
			return json(['code' => -1, 'message' => '请勿重复提交!']);
		}

    	return json((new HelpTo()) -> confirmHelpTo($post['help_to_id']));
    }
}
?>